﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;

namespace Estsh.Core.Web.Areas.Wms.Controllers.InStock
{
    [Route("wms/[controller]")]
    [ApiController]
    public class ScatteredInStockController : WmsBaseController
    {
        private IScatteredInStockService service;

        // GET: LoginController
        public ScatteredInStockController(IScatteredInStockService _service)
        {
            service = _service;
        }

        [HttpPost("GetScatteredInStockOrderList")]
        public IActionResult GetScatteredInStockOrderList(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetScatteredInStockOrderList(orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("GetScatteredInStockOrderListByOrderNo")]
        public IActionResult GetScatteredInStockOrderListByOrderNo(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetScatteredInStockOrderListByOrderNo(orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("GetLocateByName")]
        public IActionResult GetLocateByName(Newtonsoft.Json.Linq.JObject jobj)
        {
            string locateName = jobj["locateName"].ToString().Trim();
            string orderNo = jobj["orderNo"].ToString().Trim();
            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetLocateByName(locateName, orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("CheckStockByCartonAlocate")]
        public IActionResult CheckStockByCartonAlocate(Newtonsoft.Json.Linq.JObject jobj)
        {
            string cartonNo = jobj["cartonNo"].ToString().Trim();
            string locateName = jobj["locateName"].ToString().Trim();
            string orderNo = jobj["orderNo"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.CheckStockByCartonAlocate(cartonNo, locateName, orderNo, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
        [HttpPost("SetScatteredInStockOrderNoSubmit")]
        public IActionResult SetScatteredInStockOrderNoSubmit(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.SetScatteredInStockOrderNoSubmit(orderNo, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
        
    }
}
